<html>
<head><meta charset="utf-8"><title>yet another safe abstraction · wg-secure-code · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/index.html">wg-secure-code</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html">yet another safe abstraction</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="136786972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/136786972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#136786972">(Oct 30 2018 at 16:12)</a>:</h4>
<p><a href="https://www.reddit.com/r/rust/comments/9s785u/ownedalloc_a_crate_to_help_reducing_manual_memory/" target="_blank" title="https://www.reddit.com/r/rust/comments/9s785u/ownedalloc_a_crate_to_help_reducing_manual_memory/">https://www.reddit.com/r/rust/comments/9s785u/ownedalloc_a_crate_to_help_reducing_manual_memory/</a><br>
Someone's made a safe abstraction for writing lock-free data structures. Should we maybe assemble a list of such things? I just randomly stumble upon these. Once I feel I can't make my code fast without <code>unsafe</code> there is no repository of existing safe abstractions that would maybe solve my problem</p>



<a name="136805227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/136805227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Liebow-Feeser <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#136805227">(Oct 30 2018 at 20:37)</a>:</h4>
<p>I think that's a good idea. What do other folks think? It'd be nice if there were a single place to go when you want to do something unsafe and you're wondering whether there's a crate that does it for you.</p>



<a name="136807381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/136807381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#136807381">(Oct 30 2018 at 21:10)</a>:</h4>
<p>Yes, I think that'd be super helpful.</p>



<a name="136957939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/136957939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#136957939">(Nov 01 2018 at 23:39)</a>:</h4>
<p>I think we could definitely use some lists of recommended crates</p>



<a name="146860902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/146860902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> brycx <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#146860902">(Nov 06 2018 at 12:09)</a>:</h4>
<p>I just stumbled upon this crate, might be worth keeping an eye out for: <a href="https://crates.io/crates/unsafesc" target="_blank" title="https://crates.io/crates/unsafesc">https://crates.io/crates/unsafesc</a></p>



<a name="148194956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148194956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> brycx <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148194956">(Nov 22 2018 at 21:02)</a>:</h4>
<p>A  safe-ish abstraction for <code>mem::transmute</code> <a href="https://github.com/nabijaczleweli/safe-transmute-rs" target="_blank" title="https://github.com/nabijaczleweli/safe-transmute-rs">https://github.com/nabijaczleweli/safe-transmute-rs</a>.</p>



<a name="148198350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148198350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JP Sugarbroad <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148198350">(Nov 22 2018 at 22:58)</a>:</h4>
<p>Are you planning to implement alignment checks?</p>



<a name="148198460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148198460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JP Sugarbroad <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148198460">(Nov 22 2018 at 23:02)</a>:</h4>
<p>FYI armv6 says that unaligned access is <em>unpredictable</em>. <a href="https://medium.com/@iLevex/the-curious-case-of-unaligned-access-on-arm-5dd0ebe24965" target="_blank" title="https://medium.com/@iLevex/the-curious-case-of-unaligned-access-on-arm-5dd0ebe24965">https://medium.com/@iLevex/the-curious-case-of-unaligned-access-on-arm-5dd0ebe24965</a></p>



<a name="148212088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148212088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> brycx <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148212088">(Nov 23 2018 at 06:49)</a>:</h4>
<p>This isn't my crate <span class="emoji emoji-1f642" title="slight smile">:slight_smile:</span> But I'm guessing that's why the authors didn't implement alignment checks, since they support <code>no_std</code>.</p>



<a name="148212537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148212537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> brycx <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148212537">(Nov 23 2018 at 07:02)</a>:</h4>
<p>Plus, I wouldn't know how to.</p>



<a name="148272217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148272217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148272217">(Nov 24 2018 at 10:34)</a>:</h4>
<p>unaligned accesses are UB in LLVM, so it doesn't really matter what the HW does, your code could already get misoptimized before than. or is this about assembly code?</p>



<a name="148272349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148272349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148272349">(Nov 24 2018 at 10:38)</a>:</h4>
<p>Uh.... that crate has tons of soundness problems</p>



<a name="148272353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148272353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148272353">(Nov 24 2018 at 10:38)</a>:</h4>
<p>like, I can transmute <code>&amp;[u8]</code> to <code>&amp;u32</code> and alignment is not checked -&gt; insta-UB</p>



<a name="148272520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148272520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148272520">(Nov 24 2018 at 10:44)</a>:</h4>
<p>Also they seem to transmute <code>Vec</code>?!?</p>



<a name="148272588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148272588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> brycx <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148272588">(Nov 24 2018 at 10:46)</a>:</h4>
<p>Thanks for pointing that out <span class="user-mention" data-user-id="120791">@RalfJ</span>. I'm not competent enough to validate it's soundness. I wasn't aware that it was in such a bad shape...  At least it's now clear that this should not be included in a list of recommended safe abstractions!</p>



<a name="148272696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148272696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148272696">(Nov 24 2018 at 10:50)</a>:</h4>
<p>TBH I can only recommend to stay away from that crate^^</p>



<a name="148273240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148273240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148273240">(Nov 24 2018 at 11:06)</a>:</h4>
<p>I'll stop after finding one concrete example of unsoundness: <a href="https://github.com/nabijaczleweli/safe-transmute-rs/issues/35" target="_blank" title="https://github.com/nabijaczleweli/safe-transmute-rs/issues/35">https://github.com/nabijaczleweli/safe-transmute-rs/issues/35</a></p>



<a name="148288981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148288981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148288981">(Nov 24 2018 at 19:49)</a>:</h4>
<p>haha, I'm a little taken aback by "safe" and "transmute" appearing in succession</p>



<a name="148289028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148289028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148289028">(Nov 24 2018 at 19:50)</a>:</h4>
<p>also I really like how clippy tells you which transmutes can be replaced with pointer casts</p>



<a name="148289029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/yet%20another%20safe%20abstraction/near/148289029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/yet.20another.20safe.20abstraction.html#148289029">(Nov 24 2018 at 19:51)</a>:</h4>
<p>not that pointer casts are all that great either, but they seem marginally safer</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>